/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ourgame.tankgame.control;

import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.bullet.collision.PhysicsCollisionObject;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.scene.Spatial;
import com.ourgame.tankgame.behavior.LifeBehavior;
import com.ourgame.tankgame.bullet.Bullet;
import gameutil.NameMgrUtil;

/**
 * 障碍物控制
 * @author L
 */
public class BarrierControl extends RigidBodyControl implements PhysicsCollisionListener {

    public BarrierControl() {
        super(0);
    }

    BarrierControl(CollisionShape createBoxShape) {
        super(createBoxShape, 0);
    }

    @Override
    public void setPhysicsSpace(PhysicsSpace space) {
        super.setPhysicsSpace(space);
        if (space != null) {
            space.addCollisionListener(this);
        }
    }

    public void collision(PhysicsCollisionEvent event) {
        if (space == null) {
            return;
        }

        if (event.getObjectA() == this || event.getObjectB() == this) {


            if (DeathManager.processCollision(event)) {
                space.remove(this);
            }
        }

//        PhysicsCollisionObject objectA = event.getObjectA();
//        PhysicsCollisionObject objectB = event.getObjectB();
//
//
//
//        if (objectA == this || objectB == this) {
//            Spatial entryA = (Spatial) objectA.getUserObject();
//            Spatial entryB = (Spatial) objectB.getUserObject();
//
//            if (entryA instanceof LifeBehavior
//                    && entryB instanceof Bullet) {
//
//                LifeBehavior lifeObj = ((LifeBehavior) entryA);
//                Bullet bullet = ((Bullet) entryB);
//                int curLife = lifeObj.getCurLife();
//                if (curLife > 0) {
//                    
//                }
//
//
//            } else if (entryB instanceof LifeBehavior && entryB.equals(spatial)) {
//            }
//
//            if (!entryA.getName().equals("bullet")) {
//            } else if (!entryB.getName().equals("bullet")) {
//            }
//
//            space.remove(this);
//            spatial.removeFromParent();

//        }
    }
}
